﻿using System;
using System.Web.Http;

using AttributeRouting;
using AttributeRouting.Web.Mvc;
using Newtonsoft.Json.Linq;
using PH.Model.Results;
using PH.Model.Analyses.Schools;
using PH.Logic.Analyses;
namespace PH.Web.Management.Areas.Services.Controllers
{
    [RouteArea("Services")]
    [RoutePrefix("ByStudent")]
    public class ByStudentApiController : ServiceBase
    {
        [Route("GetScore")]
        [HttpPost]
        public JsonEntitySet<S4StudentModel> GetScore(JObject request)
        {
            string errinfo = "no data";
            try
            {
                base.Authorize();
                var studentno = request.Value<string>("studentno");
                var history = request.Value<bool>("studentno");
                if (!string.IsNullOrEmpty(studentno))
                {
                    var lst = SchoolLogic.GetS4Student(studentno, history);
                    return new JsonEntitySet<S4StudentModel>(lst);
                }
                else
                    throw new Utils.PhException("请提供学生身份证号码");
            }
            catch (Utils.PhException ex) { errinfo = ex.Message; }
            catch (Exception ex)
            {
                errinfo = ex.Message;
                Common.Logger.Error("", ex);
            }
            return new JsonEntitySet<S4StudentModel>(null, errinfo, false);
        }
    }
}
